﻿using Baby.Shop.Application.Contracts.Common.Helper.Linq;
using System;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;

namespace Baby.Shop.Application.Contracts.Common.Linq
{
    /// <summary>
    /// 
    /// </summary>
    public static class ExpressionHelper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="pageInput"></param>
        /// <returns></returns>
        public static Expression<Func<TSource, bool>> BuildPredicate<TSource>(QueryInput pageInput) where TSource : class, new()
        {
            return ExpressionExtension<TSource>.ExpressionSplice(pageInput.Entities);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="pageInput"></param>
        ///<param name="queryable"></param>
        /// <returns></returns>
        public static IQueryable Where<TSource>(this IQueryable queryable, QueryInput pageInput) where TSource : class, new()
        {
            return queryable.Where(ExpressionExtension<TSource>.ExpressionSplice(pageInput.Entities));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="queryable"></param>
        /// <param name="pageInput"></param>
        /// <returns></returns>
        public static IQueryable<TSource> Where<TSource>(this IQueryable<TSource> queryable, QueryInput pageInput) where TSource : class, new()
        {
            return queryable.Where(ExpressionExtension<TSource>.ExpressionSplice(pageInput.Entities));
        }
    }
}
